# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import redis

from gkcxScrapy.items import GkcxscrapyItem

def save_to_redis(conn, item):
    conn.lpush("gkcx:starturl", item["url"])

class GkcxscrapyPipeline:
    def __init__(self):
        pool = redis.ConnectionPool(host="localhost",
                                    port=6379
                                    )
        self.conn = redis.Redis(connection_pool=pool)

    def process_item(self, item, spider):
        # if isinstance(item,GkcxscrapyItem ):
        with open("b.txt", "a+") as f:
            content ="{},{},{},{},{},{}\n".format(item["name"], item["school_id"], item["num_master"], item["num_doctor"], item["num_subject"], item["num_lab"])
            f.write(content)
